-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: tree hook for persisting blocks #9365
Conversation
be1d86b
to
776bf7a
Compare
@@ -204,12 +204,14 @@ pub enum PersistenceAction { | |||
pub struct PersistenceHandle { | |||
/// The channel used to communicate with the persistence task | |||
sender: Sender<PersistenceAction>, | |||
/// The last persisted block number. | |||
last_persisted_block_number: u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes PersistenceHandle
stateful (and the methods that modify this field should receive &mut self
) let me know wdyt, maybe better to store it in the tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think so?
crates/engine/tree/src/tree/mod.rs
Outdated
@@ -342,9 +366,38 @@ where | |||
} | |||
} | |||
} | |||
|
|||
if self.should_persist() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplest possible hardcoded hook, should we use instead something similar to https://github.com/paradigmxyz/reth/tree/main/crates/consensus/beacon/src/engine/hooks ?
|
||
/// Returns the maximum block number stored. | ||
pub(crate) fn max_block_number(&self) -> BlockNumber { | ||
*self.blocks_by_number.last_key_value().unwrap_or((&BlockNumber::default(), &vec![])).0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar approach as in get_blocks_to_persist
, assuming blocks_by_number
is the source of truth for blocks to write to db, let me know if that's ok
81f40bd
to
c081a04
Compare
also added logic to remove blocks from memory after successfully persisted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should work
left a few more suggestions/nits, other than that this is what we want here
…remove_persisted_blocks_from_memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, one smol suggestion to use is_some
as in_progress
pending @Rjected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one comment about the PersistenceState
options
Closes: #9235